package com.manage.server.controller.admin;

import com.manage.dto.DepartmentDTO;
import com.manage.dto.add.DepartmentAddDTO;
import com.manage.dto.update.DepartmentUpdateDTO;
import com.manage.result.PageResult;
import com.manage.server.service.DepartmentService;
import com.manage.vo.DepartmentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.manage.result.Result;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @PostMapping
    public Result add(@RequestBody DepartmentAddDTO departmentAddDTO) {
        departmentService.save(departmentAddDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        departmentService.removeById(id);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody DepartmentUpdateDTO departmentUpdateDTO) {
        departmentService.updateById(departmentUpdateDTO);
        return Result.success();
    }

    /**
     * 多项分类分页查询
     * @param departmentDTO
     * @return
     */
    @PostMapping("/page")
    public PageResult<DepartmentVO> findDepartment(@RequestBody DepartmentDTO departmentDTO) {
        return departmentService.findDepartmentByPage(departmentDTO);
    }
}